package com.lamda.zhekou.task;

import com.alibaba.fastjson.JSONObject;
import com.lamda.zhekou.ZheKouApplication;
import com.lamda.zhekou.exception.ZheKouException;

/**
 * Created by MJiao on 15/10/8.
 */
public class CommandTask {
    /**
     * 任务的为标识
     */
    private String id;

    private String route;

    private JSONObject jsonObject;

    private CommandTask() {

    }

    public static CommandTask build(String vmId, String computerName, String route, JSONObject jsonObject) throws ZheKouException {
        CommandTask commandTask = new CommandTask();
        String taskId = computerName + "_" + vmId;
        if (ZheKouApplication.getConfigurableApplicationContext().getBean(TaskExecutorCenter.class).checkVpsHasTaskIsWaiting(taskId)) {
            throw new ZheKouException("该vps已经有相同的任务再执行,请该任务执行完成后再试.");
        }
        commandTask.setId(taskId);
        commandTask.setRoute(route);
        commandTask.setJsonObject(jsonObject);
        return commandTask;
    }

    public String getRoute() {
        return route;
    }

    public void setRoute(String route) {
        this.route = route;
    }

    public JSONObject getJsonObject() {
        return jsonObject;
    }

    public void setJsonObject(JSONObject jsonObject) {
        this.jsonObject = jsonObject;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

}
